﻿@using LaxCraft.Repositories;
@using LaxCraft.Helpers;
@{
    ViewBag.Title = "Player Detail";
}
<h2>@ViewBag.Player.Name</h2>

@foreach (var stat in ViewBag.Player.GetCompletePlayerStats(ViewBag.Stats)) {
     <div class="playerDetail">
        @{var level = stat.GetLevel();}
        @{var title = "level " + level;}
        @{var xp = "(" + stat.XP + " XP)";}
        @{var rank = LaxCraftSession.LevelTitles[level];}
        @{var src = Url.Content("~/content/images/" + level + ".png");}
        <div class="leftDetail">
            <div class="statName">@stat.Stat.Name</div>
            <div class="statDescription">@stat.Stat.Description</div>
        </div>
        <div class="levelImage">
            <img src="@src" alt="@title" title="@title" /></div>
        <div class="rightDetail">
            <div class="statTitle">@title</div>
            <div class="statXP">@xp</div>
            <div class="clearFix"></div>                                                                                        
            <div class="statRank">@rank</div>
            <div class="minXP">@stat.GetMinXP()
            </div>
            <div class="statProgressBar">
                <span class="progressBar" id="@stat.Stat.Id"></span>
            </div>
            <div class="maxXP">@stat.GetMaxXP()</div>
        </div>
       
    @if ((stat.Stat.Gem && ViewBag.Admin) || (!stat.Stat.Gem && ViewBag.Edit)) {
        @(Html.ActionLink("log new progress", "StatEntry", "Team", new { playerId = ViewBag.Player.Id, statId = stat.Stat.Id }, null))
    }
    </div>
    <div class="clearFix"></div>                                                                                        
}
<script type="text/javascript">
    $(document).ready(function () {
        var stats = new Array();

        @{   
            string script = "";
            int i = 0;
         }

        @foreach (var stat in ViewBag.Player.GetCompletePlayerStats(ViewBag.Stats)) {
            script += "var stat" + stat.Stat.Id + "=new Object();";
            script += "stat" + stat.Stat.Id + "[\"Percent\"]=" + stat.GetXPPercent() + ";";

            script += "stats[" + i + "]=stat" + stat.Stat.Id + ";";
            i++;
        }

        @MvcHtmlString.Create(script);

        $('.progressBar').each(function(index) {
            $(this).progressBar(stats[index].Percent);
        });

    });
</script>